#pragma once
#include<SockEvent.h>
class SocketServer{
    Socket * socket;
    sockaddr_in * socketSet;
    SockEvent event;
    int setLen;
    public:
    SocketServer(){
        socket = nullptr;
    }
    SocketServer(Socket * sock,int len=10):socket(sock){}
    int listen(int);
    void start(CallBackType);
};

int SocketServer::listen(int backlog=20){
    socket->SockStartup();
    if (::bind(socket->Sock, (sockaddr*)&socket->sockAddr, sizeof(socket->sockAddr)) == SOCKET_ERROR){
        socket->err = 3;            //异常处理
        return 1;
    }
    if(::listen(socket->Sock,backlog) == SOCKET_ERROR){
        socket->err = 4;
        return 1;
    }
}

void SocketServer::start(CallBackType fun){
    event.setCallBack(fun);
}